<?php
require("libraries/agency.php");
class User extends Agency{
	public function __construct(){
		parent::__construct();
		$this->load->model("model_user");
		$this->load->model("muser");
		$this->_user = $this->session->userdata('ses_userid');
	}
	public function index(){
		$id = $this->_user;
		$data['title'] = "Manage your profile";
		$data['template'] = "users/edit_user";
		$data['act'] = 2;
		$data['data'] = "";
		$data['listall'] = $this->listcruis($this->_user);
		$data['info'] = $this->model_user->getdata($id);
		$this->load->view("layout",$data);
	}
	public function ajax(){
		$id = $this->_user;
		$pass = $_POST['password'];
		$email = $_POST['email'];
		$fullname = $_POST['fullname'];
		$phone = $_POST['phone'];
		$address = $_POST['address'];
		$null = "/^[a-zA-Z]{1}[a-zA-Z0-9._]{3,25}\@[a-zA-Z0-9]{3,}\.[a-zA-Z.]{2,8}$/";
		if(preg_match($null,$email)){
			$emailadd = $this->muser->check_email($email,$id);
			if($emailadd == FALSE){
				echo "This email areaded exits!";
			}else{
				$db = array(
					"name" => $fullname,
					"phone" => $phone,
					"adress" => $address,
					"email" => $email
				);
				if($pass != ""){
					$db['password'] = md5($pass);
				}
				$this->muser->update($db,$id);
				echo "true";
			}
		}else{
			echo "Email is invalid";
		}
	}
}
?>